<?php

class training_model extends \swap\rdb_model {
    
    const name_length = 45;
    const address_length = 255;
    const course_length = 45;
    const certificate_length = 45;
    const introduction_length = 500;
    
    // 规则
    public static function prop_rules($operation) {
        $start_time = array(
            'start_time' => array(
                'change_to' => 'string',
                'cannot_be' => array('', '请选择起始时间!'),
            ),
        );
        
        $end_time = array(
            'end_time' => array(
                'change_to' => 'string',
                'cannot_be' => array('', '请选择结束时间!'),
            ),
        );
            
        $name = array(
            'name' => array(
                'change_to' => 'string',
                'cannot_be' => array('', '请输入培训机构名称'),
                'char_size' => array(6, self::name_length, '机构名称长度介于%d与%d个字符'),
            ),
        );
        
        $address = array(
            'address' => array(
                'change_to' => 'string',
                'pass_if_be' => '',
                'char_size' => array(6, self::address_length, '地址长度介于%d与%d个字符'),
            ),
        );
        
        $course = array(
            'course' => array(
                'change_to' => 'string',
                'cannot_be' => array('', '请输入课程名称'),
                'char_size' => array(6, self::course_length, '课程长度介于%d与%d个字符'),
            ),
        );
        
        $certificate = array(
            'certificate' => array(
                'change_to' => 'string',
                'pass_if_be' => '',
                'char_size' => array(6, self::certificate_length, '证书长度介于%d与%d个字符'),
            ),
        );
        
        $introduction = array(
            'introduction' => array(
                'change_to' => 'string',
                'pass_if_be' => '',
                'char_size' => array(6, self::introduction_length, '详细描述长度介于%d与%d个字符'),
            ),
        );
        
        $rules = array(
            'new' => $start_time + $end_time + $name + $address + $course + $certificate + $introduction,
            'edit' => $start_time + $end_time + $name + $address + $course + $certificate + $introduction,
        );
        
        return $rules[$operation];
    }
    
    // 辅助api
    public static function format_time($timestamp) {
        return date('Y-m-d', $timestamp);
    }
    
}